package com.sys.sprinngboot.goodtheater.config;

import com.sys.sprinngboot.goodtheater.component.UserInterceptor;
import com.sys.sprinngboot.goodtheater.utils.Myproperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Autowired
    private Myproperties myproperties;

    @Autowired
    UserInterceptor userInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**").addResourceLocations(
                "file:" + myproperties.getFilepath() + File.separator);

    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index.html").setViewName("movie-list");
        registry.addViewController("/main.html").setViewName("movie-list");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptor).addPathPatterns("/book*")
                .addPathPatterns("/ticket").addPathPatterns("order");
    }
}
